﻿using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using WebMvc.Utils.ConfigurationInfo;

namespace WebMvc.Controllers
{
    public class A03ReturnValueController : Controller
    {
        public A03ReturnValueController()
        { }

        /// <summary>
        /// 返回视图
        /// </summary>
        /// <param name="optionsMonitor"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public IActionResult Index([FromServices] IOptionsMonitor<ConnectionStringOptions> optionsMonitor, [FromServices] IOptions<ConnectionStringOptions> options)
        {
            return View();

            // 指定视图文件
            // return View("~/Views/A03ReturnValue/IndexView.cshtml");

            // 指定视图文件和Model
            //return View("~/Views/A03ReturnValue/IndexView.cshtml", optionsMonitor.CurrentValue);
        }

        /// <summary>
        /// 返回JSON对象
        /// </summary>
        /// <param name="optionsMonitor"></param>
        /// <param name="options"></param>
        /// <returns></returns>
        public IActionResult Json([FromServices] IOptionsMonitor<ConnectionStringOptions> optionsMonitor, [FromServices] IOptions<ConnectionStringOptions> options)
        {
            return Json(optionsMonitor.CurrentValue);
        }
    }
}
